Lab 10: advanced tricks for browsing, loading and manipulating files There is a accompanying data zip containing a couple of text files. Unpack the zip and run vim from this directory. Remember that you can check the list of open buffers at any time with :ls or :buffers 1. wildcards a) start vim in the root of the unpacked data zip b) use at least one wildcard to open hello.sh c) use the find command, to open bullets.sh in the root without specifying the extension d) use the find command, to open udemi/success.txt using only the base name "success". e) open all .txt files in the root f) open all .txt files at any nested depth g) open all .txt files nested under udemi h) open index.txt and open one of the paths, go back to index and open another path in a split. i) are path and suffixesadd the only options relevant to gf? 2. bufdo & argdo a) open a fresh vim session with happy.txt and numbers.txt as arguments b) use edit to open index.txt as well c) which files will be modified by :hide bufdo delete? d) which files will be modified by :hide argdo delete? e) change the argument list to happy.txt and index.txt without leaving vim f) which buffers are open now? g) yank the 3rd line of every file in the argument list h) what happens if you do a put now? 3. global a) open a fresh vim session with happy.txt and move the lines containing "com" to the end of the document b) delete all other lines c) reload the original file, then replace "ble" with "bla", but only on the lines not containing "ted" d) use :normal to delete the trailing comma's only on the lines containing bla 4. vimgrep a) open a fresh vim session and use vimgrep to find occurrences of leg b) go through the matches one by one, until vim tells you there are "No more items" c) go back to the first match d) now open the quickfix menu and jump to another result e) how do you select another result through the quickfix window, without calling copen again? f) use cfdo to replace all occurrences of leg with arm g) what is the difference between :vimgrep /place/g **/*.txt | :cdo s/place/location/ :vimgrep /place/ **/*.txt | :cdo s/place/location/g h) what is the difference between :vimgrep /place/g **/*.txt | :cdo s/place/placemat/ :vimgrep /place/ **/*.txt | :cdo s/place/placemat/g ↓↓↓ answers below ↓↓↓ 1. wildcards a) vim b) the possibilities are endless :e hello??? :e hel* :e h[eo]ll[eo].sh c) either set the suffixesadd directly in vim or in the vimrc :set suffixesadd=.sh :find bullets d) one of :set path=udemi :set suffixesadd=.txt :find success :set path=** :set suffixesadd=.txt :find success to combine the suffixes with the one from before :set suffixesadd=.sh,.txt e) one of :next *.txt :args *.txt :n *.txt :ar *.txt f) one of :next **/*.txt :arg **/*.txt g) one of :next udemi/**/*.txt :arg udemi/**/*.txt note: "udemi/" is required, or you will open all text files, not just the ones in the udemi dir. h) sequentually :e index.txt gf ctrl-o j ctrl-w, f i) the solution to this exercise is to use :help gf which tells you, that there are 2 additional relevant properties: isfname & includeexpr 2. bufdo & argdo a) vim happy.txt numbers.txt b) :edit index.txt c) happy.txt, numbers.txt & index.txt d) happy.txt, numbers.txt index.txt wasn't added to the argument list, because the edit command doesn't change the argument list. You can check the argument list at any time with :args e) any of :args happy.txt index.txt :ar ha* i* f) still all 3 files happy.txt numbers.txt & index.txt we only changed the argument list, not the open buffers in this case g) :argdo 3 yank h) Only the last line yanked, would be inserted. It has overwritten the previous yanked line. 3. global a) one of :global /com/ move $ :g/com/m$ or in two steps: /com :g//m$ b) one of :global! /com/ delete :vglobal /com/ delete :g!/com/d :v/com/d :g!//d :v//d c) :e! to load, or just repeat 'u' to undo, then one of :global! /ted/ substitute/ble/bla/g :vglobal /ted/ substitute/ble/bla/g :g!/ted/s/ble/bla/g :v/ted/s/ble/bla/g d) one of :global /bla/ normal $x :global /bla/ normal $X :g/bla/norm$x :g/bla/norm$X 4. vimgrep a) one of :vimgrep /leg/g ** :vim/leg/g ** b) one of :cnext (x5) :cn (x5) c) one of :cprevious (x4) :cp (x4) :cfirst :cfir d) :copen (move the cursor, then) e) same as before, but you need to use the window shortcuts to jump back to the quickfix menu, examples: ctrl-w, ctrl-w ctrl-w, w ctrl-w, ctrl-w, j f) cfdo %s/leg/arm/g g) they perform the same substitution, but their usage of the quickfix list is different. :vimgrep /place/g **/*.txt | :cdo s/place/location/ will add every occurrence of the word place to the quickfix list. Then it will run the substitution command for every entry, replacing all occurrences of the word "place" :vimgrep /place/ **/*.txt | :cdo s/place/location/g will only add every line containing the word "place" once. Then it will run a substitution on every one of these lines, which performs all occurrences on the line in one command. The end result is the same, except that there are less entries in the quickfix list. h) Same answer, with a twist. Since the replacement word "placemat" contains the search word "place" :vimgrep /place/g | :cdo s/place/placemat/ will lead to strange results. If there are more occurrences of "place" on a line, then the repeated substitution will keep changing the first word: place -> placemat -> placematmat -> placematmatmat Later occurrences of the word "place" on a line will remain unchanged as "place". The other answer: :vimgrep /place/ **/*.txt | :cdo s/place/placemat/g correctly replaces every occurrence of place with placemat.